package
{
	import flash.display.Sprite;

	public class AstarList
	{
		public var nodeList:ListSearchStructure;
		public var spatialIndex:QuadTreeSpatialIndex;
		
		public function AstarList()
		{
			nodeList = new ListSearchStructure();
			spatialIndex = new QuadTreeSpatialIndex(Global.WORLD_RECT.size);
		}
		
		
		public function getDebugImage():Sprite{
			var spr:Sprite = new Sprite();
			var i:int, il:int;
			for(i = 0, il = nodeList.numObjects(); i < il; i++){
				var node:AstarNode = nodeList.getAllNodes()[i] as AstarNode;
				spr.addChild(node.getDebugImage(0x777777));
			}
			
			return spr;
		}
		public function contains(node:AstarNode):Boolean{
			
			var test:Boolean = spatialIndex.find(node);
			
			return test;
			
			
			var found:Boolean = false;
			var i:int, il:int;
			for(i = 0, il = nodeList.numObjects(); i < il; i++){
				if((nodeList.getAllNodes()[i] as AstarNode).location.equals(node.location)){
					found = true;
				}
			}			
			
			return found;
		}
		
		public function add(node:AstarNode):void{
			nodeList.add(node);
			spatialIndex.add(node);
		}
		
		public function remove(node:AstarNode):void{
			nodeList.remove(node)
			spatialIndex.remove(node);
		}
		
		public function isEmpty():Boolean{
			return nodeList.isEmpty();
		}
		
		public function getBestNode():AstarNode{
			return nodeList.getBestNode() as AstarNode;
		}
	}
}